package com.nexgo.payment.trans;

import android.support.annotation.NonNull;

import com.nexgo.payment.BaseTransPresenter;
import com.nexgo.payment.BaseTransView;
import com.nexgo.payment.action.ActionResult;
import com.nexgo.payment.aop.annotation.RunOnMainThread;
import com.nexgo.payment.databases.DataSource;
import com.nexgo.payment.entity.TransData;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Created by xiaox on 2017/9/12.
 */

public abstract class AbsBaseTransPresenter implements BaseTransPresenter {
    private final Logger mLog = LoggerFactory.getLogger(AbsBaseTransPresenter.class.getSimpleName());

    protected final BaseTransView mView;
    protected final DataSource mRepository;
    protected TransData mTransData;

    @SuppressWarnings("unchecked")
    protected AbsBaseTransPresenter(@NonNull BaseTransView view, @NonNull DataSource repository) {
        mView = checkNotNull(view);
        mRepository = checkNotNull(repository);
        mView.setPresenter(this);
        mTransData = getTransData();
    }

    /**
     * 获取交易开始的数据采集实例
     *
     * @return 交易信息采集实例
     */
    protected abstract TransData getTransData();

    @Override
    public void start() {

    }

    @Override
    public void pause() {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void importActionResult(ActionResult actionResult) {

    }

    @Override
    public void cancelProcess() {

    }

    /**
     * 主线程运行
     *
     * @param runnable
     */
    @RunOnMainThread
    protected void postMainThread(Runnable runnable) {
        runnable.run();
    }
}
